package com.pfs.internal.timestamp.reports;

import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.usermodel.Workbook;

public abstract class PfsReadExcel<T> {
	private Workbook wb;
	protected int startRow;

	public ArrayList<T> readSheet(HSSFSheet sheet) throws Exception {
		ArrayList<T> arr = null;
		int count = sheet.getPhysicalNumberOfRows();
		try {
			arr = new ArrayList<T>();
			for (int i = startRow; i < count; i++) {
				HSSFRow row = sheet.getRow(i);
				List<T> models = readRow(row, i);
				if (models != null && models.size() > 0) {
					arr.addAll(models);
				}
			}
		} catch (Exception e) {
			throw e;
		}
		return arr;
	}

	public abstract List<T> readRow(HSSFRow row, int rn) throws Exception;

	public int getStartRow() {
		return startRow;
	}

	public abstract void setStartRow(int startRow);

	public Workbook getWb() {
		return wb;
	}

	public void setWb(Workbook wb) {
		this.wb = wb;
	}
}
